﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2014-083-29 12:45
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using BassDrop.Core.Common.Services;

namespace BassDrop.DesktopClient.Services
{
	/// <summary>
	/// Desktop implementation of the IUserInterface
	/// </summary>
	public class UserInterface : IUserInterface
	{
		/// <summary>
		/// Display a message box to the user with the specified message and options and wait for them to close it. Return which button the user clicked.
		/// </summary>
		/// <param name="messageBoxText">The text to display in the message box.</param>
		/// <param name="caption">The title / caption of the message box.</param>
		/// <param name="button">The buttons of the message box.</param>
		/// <param name="icon">The icon in the message box. May not be supported on all platforms, then it does nothing. Default is no image.</param>
		/// <returns></returns>
		public PortableMessageBoxResult ShowMessageBox( string messageBoxText, string caption, PortableMessageBoxButton button, PortableMessageBoxImage icon = PortableMessageBoxImage.None )
		{
			MessageBoxButton btn;
			MessageBoxImage img;

			switch ( button )
			{
				default: /* fallthrough */
				case PortableMessageBoxButton.OK:
					btn = MessageBoxButton.OK;
					break;
				case PortableMessageBoxButton.OKCancel:
					btn = MessageBoxButton.OKCancel;
					break;
				case PortableMessageBoxButton.YesNo:
					btn = MessageBoxButton.YesNo;
					break;
				case PortableMessageBoxButton.YesNoCancel:
					btn = MessageBoxButton.YesNoCancel;
					break;
			}

			switch ( icon )
			{
				case PortableMessageBoxImage.Asterisk:
					img = MessageBoxImage.Asterisk;
					break;
				case PortableMessageBoxImage.Error:
					img = MessageBoxImage.Error;
					break;
				case PortableMessageBoxImage.Exclamation:
					img = MessageBoxImage.Exclamation;
					break;
				case PortableMessageBoxImage.Hand:
					img = MessageBoxImage.Hand;
					break;
				case PortableMessageBoxImage.Information:
					img = MessageBoxImage.Information;
					break;
				case PortableMessageBoxImage.Question:
					img = MessageBoxImage.Question;
					break;
				case PortableMessageBoxImage.Stop:
					img = MessageBoxImage.Stop;
					break;
				case PortableMessageBoxImage.Warning:
					img = MessageBoxImage.Warning;
					break;
				default: /* fallthrough */
				case PortableMessageBoxImage.None:
					img = MessageBoxImage.None;
					break;
			}

			MessageBoxResult result = MessageBox.Show( App.Instance.MainWindow, messageBoxText, caption, btn, img );

			switch ( result )
			{
				case MessageBoxResult.Cancel:
					return PortableMessageBoxResult.Cancel;
				case MessageBoxResult.No:
					return PortableMessageBoxResult.No;
				case MessageBoxResult.OK:
					return PortableMessageBoxResult.OK;
				case MessageBoxResult.Yes:
					return PortableMessageBoxResult.Yes;
				default: /* fallthrough */
				case MessageBoxResult.None:
					return PortableMessageBoxResult.None;
			}
		}
	}
}
